package com.party.core.service.logistics.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.logistics.WlLogisticsReadDao;
import com.party.core.dao.write.logistics.WlLogisticsWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.logistics.WlLogistics;
import com.party.core.service.logistics.IWlLogisticsService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @Author: Administrator.
 * @Description: 商城物流
 * @Date:Created in 2017/9/6 0006 上午 10:17.
 */
@Service
public class WlLogisticsService implements IWlLogisticsService {
    @Autowired
    private WlLogisticsReadDao wlLogisticsReadDao;
    @Autowired
    private WlLogisticsWriteDao wlLogisticsWriteDao;

    /**
     * 商城物流插入
     *
     * @param wlLogistics 商城物流
     * @return 插入编号
     */
    @Override
    public String insert(WlLogistics wlLogistics) {
        BaseModel.preInsert(wlLogistics);
        boolean result = wlLogisticsWriteDao.insert(wlLogistics);
        if (result) {
            return wlLogistics.getId();
        }
        return null;
    }

    /**
     * 更新商城物流
     *
     * @param wlLogistics 商城物流
     * @return 更新结果（true/false）
     */
    @Override
    public boolean update(WlLogistics wlLogistics) {
        wlLogistics.setUpdateDate(new Date());
        return wlLogisticsWriteDao.update(wlLogistics);
    }

    /**
     * 逻辑删除商城物流
     *
     * @param id 实体主键
     * @return 删除结果（true/false）
     */
    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return wlLogisticsWriteDao.deleteLogic(id);
    }

    /**
     * 物理删除商城物流
     *
     * @param id 实体主键
     * @return 删除结果（true/false）
     */
    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return wlLogisticsWriteDao.delete(id);
    }

    /**
     * 批量逻辑删除
     *
     * @param ids 主键集合
     * @return 删除结果（true/false）
     */
    @Override
    public boolean batchDeleteLogic(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return wlLogisticsWriteDao.batchDeleteLogic(ids);
    }

    /**
     * 批量物理删除
     *
     * @param ids 主键集合
     * @return 删除结果（true/false）
     */
    @Override
    public boolean batchDelete(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return wlLogisticsWriteDao.batchDelete(ids);
    }

    /**
     * 获取商城物流
     *
     * @param id 主键
     * @return 商城物流
     */
    @Override
    public WlLogistics get(String id) {
        return wlLogisticsReadDao.get(id);
    }

    /**
     * 分页查询
     *
     * @param wlLogistics 商城物流
     * @param page        分页信息
     * @return 商城物流列表
     */
    @Override
    public List<WlLogistics> listPage(WlLogistics wlLogistics, Page page) {
        return wlLogisticsReadDao.listPage(wlLogistics, page);
    }

    /**
     * 查询所有商城物流
     *
     * @param wlLogistics 商城物流
     * @return 商城物流列表
     */
    @Override
    public List<WlLogistics> list(WlLogistics wlLogistics) {
        return wlLogisticsReadDao.listPage(wlLogistics, null);
    }

    @Override
    public List<WlLogistics> batchList(@NotNull Set<String> ids, WlLogistics wlLogistics, Page page) {
        return null;
    }

    @Override
    public Integer getCountByOrderId(String orderId, Integer status) {
        Integer count = wlLogisticsReadDao.getCountByOrderId(orderId, status);
        return null == count ? 0 : count;
    }
}
